package com;

import java.awt.Point;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class AlwaysTurnLeft {
	private static Scanner scanner;
	private ArrayList<Room> rooms = new ArrayList<Room>();
	private int lastDirection = 2;
	private Point lastPoint = null;
	Map<String, String> description = new HashMap<String, String>();

	public static void main(String[] args) {
		AlwaysTurnLeft alwaysTurnLeft = new AlwaysTurnLeft();		
		try {
			BufferedWriter output = new BufferedWriter(new FileWriter("out.txt"));
			scanner = new Scanner(new File("input//B-large-practice.in"));//get the scanner
			int testCases = scanner.nextInt();//number of test cases
			scanner.nextLine();
			alwaysTurnLeft.initializeMap();
			for(int testCase=0; testCase<testCases;testCase++) {
				alwaysTurnLeft.rooms.clear();				
				String[] path = scanner.nextLine().split(" ");
				alwaysTurnLeft.goForward(path[0].substring(1, path[0].length()), 2, new Point(0,0));
				alwaysTurnLeft.goForward(path[1].substring(1, path[1].length()), alwaysTurnLeft.lastDirection, alwaysTurnLeft.lastPoint);
				Collections.sort(alwaysTurnLeft.rooms);
				output.write("Case #"+(testCase+1)+":\n");
				output.write(alwaysTurnLeft.getString());
				output.flush();				
			}
			output.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	class Room implements Comparable<Object>{
		Point position = null;
		int[] directions = {0,0,0,0};
		
		public Room(int x, int y){
			position = new Point(x, y);
		}
		
		public void allowWalk(int direction){
			switch (direction) {
			case 0:
				directions[0] = 1;
				break;
			case 1:
				directions[1] = 1;
				break;
			case 2:
				directions[2] = 1;
				break;
			case 3:
				directions[3] = 1;
				break;
			default:
				break;
			}
		}
	
		public boolean equals(Object object){
			Room room = (Room)object;
			if(room.position.equals(this.position))
				return true;
			return false;
		}

		public int compareTo(Object o) {
			Room room = (Room)o;
			if(this.position.y < room.position.y )
				return -1;
			else if(this.position.y > room.position.y )
				return 1;
			else{
				if(this.position.x < room.position.x)
					return 1;
				else if(this.position.x < room.position.x)
					return -1;
				else return 0;
			}
		}
		
		public String getDescription() {
			String des = "";
			for(int i=0;i<directions.length;i++){
				des += directions[i];
			}
			return des;
		}
	}

	private void goForward(String path, int direction, Point startPoint){
		int startDirection = direction;
		int x = startPoint.x, y = startPoint.y;
		char[] steps = path.toCharArray();
		
		for(int i=0; i<steps.length;i++){
			char key = steps[i];
			switch (key) {
			case 'W':
				Room newRoom = new Room(x,y);
				if(rooms.contains(newRoom))
					newRoom = rooms.remove(rooms.indexOf(newRoom));
				
				switch (startDirection) {
				case 0:
					y -= 1;
					newRoom.allowWalk(0);
					break;
				case 1:
					x -= 1;
					newRoom.allowWalk(3);
					break;
				case 2:
					y += 1;
					newRoom.allowWalk(1);
					break;
				case 3:
					x += 1;
					newRoom.allowWalk(2);
					break;
				default:
					break;
				}
				rooms.add(newRoom);
				break;
			case 'R':
				startDirection = (startDirection + 1)% 4;
				break;
			case 'L':
				startDirection = (startDirection + 3)% 4;
				break;
			default:
				break;
			}
		}
		lastDirection = (startDirection + 2)%4;
		switch (lastDirection) {
		case 0:
			lastPoint = new Point(x, y-1);
			break;
		case 1:
			lastPoint = new Point(x-1,y);
			break;
		case 2:
			lastPoint = new Point(x,y+1);
			break;
		case 3:
			lastPoint = new Point(x+1, y);
			break;
		default:
			break;
		}
	}

	private String getString(){
		String description = "";
		int columns = rooms.get(0).position.x + 1 - rooms.get(rooms.size()-1).position.x;
		int ro =0;
		for(Room room:rooms){			
			if(ro%columns == 0 && ro != 0)description += "\n";
			description += getLetter(room.getDescription());
			ro++;
		}		
		return description+"\n";
	}
	
	private void initializeMap(){
		description.put("1000", "1");
		description.put("0100", "2");
		description.put("1100", "3");
		description.put("0010", "4");
		description.put("1010", "5");
		description.put("0110", "6");
		description.put("1110", "7");
		description.put("0001", "8");
		description.put("1001", "9");
		description.put("0101", "a");
		description.put("1101", "b");
		description.put("0011", "c");
		description.put("1011", "d");
		description.put("0111", "e");
		description.put("1111", "f");
	}
	
	private String getLetter(String desc){
		return description.get(desc);
	}
	
}
